function themanh(){
    var path = $("#imgproduct").val();
    var ProductID = $("#ProductID").val();
    $("#ajaxload").html('<image src="'+url+'templates/images/loading.gif">');
    $.post(url+"product/add_img_product",{'path':path,'ProductID':ProductID},function(data)
    {
        $("#listimg").html(data);
        $("#imgproduct").val('');
        $("#ajaxload").html('');
                                                       
    });    
}

function lastorder(){
    $("#orderlast").html('<image src="'+url+'templates/images/loading.gif">');
    $.post(url+"ajax/orderlast",{},function(data)
    {
        $("#orderlast").html(data);                                               
    });     
}

function changestatus(value,id){
    $("#loadstatus"+id).html('<image src="'+url+'templates/images/loading1.gif">');
    $.post(url+"order/changestatus",{'status':value,'id':id},function(data)
    {
        $("#loadstatus"+id).html('');  
                                                     
    },'json');    
}
/******
* Tuy chon xem don hang e-com
*/

function change_list_order(status){
    $("#ajax-load").css('display','block');
    $.post(url+"order/change_list_order",{'status':status},function(data)
    {
        $("#page").html(data.list);  
        $("#pagination_top").html(data.pagination);  
        $("#pagination_bot").html(data.pagination);  
        $("#num_top").html(data.num);  
        $("#num_bot").html(data.num);  
        $("#status").val(data.status);  
        $("#ajax-load").css('display','none');
                                                     
    },'json');    
}
/********
* Tùy chọn xem don hang nhom mua
*/
function change_list_order_groupby(status){
    $("#ajax-load").css('display','block');
     var cartid = $('#CartID').val(); 
     var customer = $("#Pay_FullName").val();
     var datebegin = $("#DateBegin").val();
     var dateend = $("#DateEnd").val();    
     var order_name = $("#order_name").val();    
     var order_value = $("#order_value").val();  
    
    $.post(url+"donhang/change_list_order",{'status':status,'cartid':cartid, 'customer':customer,'datebegin':datebegin,'dateend':dateend,'order_value':order_value,'order_name':order_name},function(data)
    {
        $("#page").html(data.list);  
        $("#pagination_top").html(data.pagination);  
        $("#pagination_bot").html(data.pagination);  
        $("#num_top").html(data.num);  
        $("#num_bot").html(data.num);  
        $("#status").val(data.status);  
        $("#order_name").val(data.order_name);  
        $("#order_value").val(data.order_value);  
        $("#ajax-load").css('display','none');
                                                     
    },'json');    
}

/**********
* Thong bao chuyen khoan moi nhat
*/
// Sap xep don hang nhóm mua

function order_buy(order_name){
    $("#ajax-load").css('display','block');
    status = $("#status").val();
    order_value = $("#order_value").val();
    $.post(url+"donhang/change_list_order",{'status':status,'order_name':order_name,'order_value':order_value,'static':1},function(data)
    {
        $("#page").html(data.list);  
        $("#pagination_top").html(data.pagination);  
        $("#pagination_bot").html(data.pagination);  
        $("#num_top").html(data.num);  
        $("#num_bot").html(data.num);  
        $("#status").val(data.status);  
        $("#order_name").val(data.order_name);  
        $("#order_value").val(data.order_value);  
        $("#ajax-load").css('display','none');
                                                     
    },'json');
}

// Sap xep don hang  e-com

function order(order_name){
    $("#ajax-load").css('display','block');
    status = $("#status").val();
    order_value = $("#order_value").val();
    $.post(url+"order/change_list_order",{'status':status,'order_name':order_name,'order_value':order_value,'static':1},function(data)
    {
        $("#page").html(data.list);  
        $("#pagination_top").html(data.pagination);  
        $("#pagination_bot").html(data.pagination);  
        $("#num_top").html(data.num);  
        $("#num_bot").html(data.num);  
        $("#status").val(data.status);  
        $("#order_name").val(data.order_name);  
        $("#order_value").val(data.order_value);  
        $("#ajax-load").css('display','none');
                                                     
    },'json');
}

function transfer_notice_last(){
    $("#transfer_notice").html('<image src="'+url+'templates/images/loading.gif">');
    $.post(url+"ajax/transfer_notice_last",{},function(data)
    {
        $("#transfer_notice").html(data.list);                                               
    },'json');    
}




function loadstatic(){
    $("#static").html('<image src="'+url+'templates/images/loading.gif">');
    $.post(url+"ajax/thongke",{},function(data)
    {
        $("#static").html(data);                                               
    });     
}

//Site config
function loadConfig(){
    $("#config").html('<image src="'+url+'templates/images/loading.gif">');
    $.post(url+"siteconfig/config",{},function(data)
    {
        $("#config").html(data);                                               
    });    
}

//Member
function updatemember(id){
    $("#page").html('<image src="'+url+'templates/images/loading.gif">');
    $.post(url+"member/update/",{'id':id},function(data)
    {
        $("#page").html(data);                                               
    });     
}

//Publish
function publish(table,field,id,status){
    $("#publish"+id).html('<image src="'+url+'templates/images/loading1.gif">');
    $.post(url+"ajax/publish/",{'table':table,'field':field,'id':id,'status':status},function(data)
    {
        $("#publish"+id).html(data);                                               
    });     
}
//Approve
function approve(table,field,id,status){
    $("#approve"+id).html('<image src="'+url+'templates/images/loading1.gif">');
    $.post(url+"ajax/approve/",{'table':table,'field':field,'id':id,'status':status},function(data)
    {
        $("#approve"+id).html(data);                                               
    });     
}
//Get Alias

function getalias_(){
    var name = $('#name').val();
    $.post(url+"ajax/getalias/",{'name':name},function(data)
    {
        $("#alias").val(data);                                               
    });     
}
$(function(){
    $("#title").keyup(function()
    {
        var word=$(this).val();
        $.post(url+"ajax/getalias/",{'name':word},function(data)
        {
            $("#alias").val(data);
        });
        return false;
    });
});

$(function(){
    $("#DiscountPercent").keyup(function(){
        var discount = $(this).val();
        if(discount.length > 2){
            alert('Vui lòng nhập phần trăm giảm giá nhỏ hơn 2 chữ số');
        }
        var price = $("#Price").val();
        if(price ==''){
            alert('Vui lòng nhập giá để tính được số tiền giảm giá');
        }else{
            var price_new = (discount * price)/100 ;
        $("#label_discount").html(price_new+' VNĐ')   
        }
    });
});

function add_rates(){
     $("#ratesform").validate({
        rules: {
            ProductsWeight: "required",
            PriceShip: "required"
        },
        messages: {
            ProductsWeight: "Vui lòng nhập tổng trọng lượng đơn hàng",
            PriceShip: "Vui lòng nhập phí vận chuyển"
        }
        ,submitHandler: function(form) {
             var ProductsWeight = $("#ProductsWeight").val();
             var PriceShip= $('#PriceShip').val();          
             var ship_city= $('#ship_city').val();          
             var ShippingType= $('#ShippingType').val();          
             var ship_country= $('#ship_country').val();          
            $("#ajax-load").css('display','block');
            $.post(url+"country/add_rates",{'ShippingType':ShippingType,'ProductsWeight':ProductsWeight,'PriceShip':PriceShip,'ship_city':ship_city,'ship_country':ship_country},function(data)
            {
                
                $("#list_rates").html(data.list);   
                $("#ajax-load").css('display','none');                                             
            },'json')
            }
    });    

}
function delshipping(id){
        $("#ajax-load").css('display','block');
        $.post(url+"country/delshipping",{'id':id},function(data)
        {           
            $('tr#ship'+id).animate({opacity:"hide"}, "slow").remove();
            alert('Xóa thành công');
            $("#ajax-load").css('display','none');                                             
        },'json');         
}
function show_hide_tag(tag_show){
    $("#"+tag_show).toggle();
}

